package c.f.c.a.j;

import c.f.c.a.b;
import c.f.c.a.d;
import c.f.c.a.e;
import c.f.c.a.h;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;

public final class f<TResult> extends c.f.c.a.f<TResult> {
    public final Object a = new Object();
    public boolean b;
    public volatile boolean c;
    public TResult d;
    public Exception e;
    public List<b<TResult>> f = new ArrayList();

    public final c.f.c.a.f<TResult> a(d dVar) {
        b(h.d.c, dVar);
        return this;
    }

    public final c.f.c.a.f<TResult> b(Executor executor, d dVar) {
        h(new c(executor, dVar));
        return this;
    }

    public final c.f.c.a.f<TResult> c(e<TResult> eVar) {
        d(h.d.c, eVar);
        return this;
    }

    public final c.f.c.a.f<TResult> d(Executor executor, e<TResult> eVar) {
        h(new e(executor, eVar));
        return this;
    }

    public final Exception e() {
        Exception exception;
        synchronized (this.a) {
            exception = this.e;
        }
        return exception;
    }

    public final TResult f() {
        Object obj;
        synchronized (this.a) {
            if (this.e == null) {
                obj = this.d;
            } else {
                throw new RuntimeException(this.e);
            }
        }
        return obj;
    }

    public final boolean g() {
        boolean z;
        synchronized (this.a) {
            z = this.b && !this.c && this.e == null;
        }
        return z;
    }

    public final c.f.c.a.f<TResult> h(b<TResult> bVar) {
        boolean z;
        synchronized (this.a) {
            synchronized (this.a) {
                z = this.b;
            }
            if (!z) {
                this.f.add(bVar);
            }
        }
        if (z) {
            bVar.onComplete(this);
        }
        return this;
    }

    public final void i() {
        synchronized (this.a) {
            for (b onComplete : this.f) {
                try {
                    onComplete.onComplete(this);
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e2) {
                    throw new RuntimeException(e2);
                }
            }
            this.f = null;
        }
    }
}
